﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HR_Implements;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace HostApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        TcpChannel channel = null;
        private void btn_start_Click(object sender, EventArgs e)
        {
           
            try
            {
                //1. Create Channel
               // channel = new TcpChannel(int.Parse(txt_employee.Text));
                //2. Register Channel
                BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
                serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                System.Collections.IDictionary props = new System.Collections.Hashtable();
                props["port"] = txt_employee.Text;

                channel = new TcpChannel(props, null, serverProvider);
                ChannelServices.RegisterChannel(channel);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(EmployeeRemotingObject), "EmployeesRemotingObject", WellKnownObjectMode.SingleCall);
                
                toolStripLabel1.Text = "Start";
            }
            catch (Exception ex)
            {
                toolStripLabel1.Text = "Error";
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_stop_Click(object sender, EventArgs e)
        {
            try
            {
                ChannelServices.UnregisterChannel(channel);
                toolStripLabel1.Text = "Stop";
            }
            catch (Exception ex)
            {
                toolStripLabel1.Text = "Error";
                MessageBox.Show(ex.Message);
            }
        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {

        }
    }
}
